export default {
	get(url, data) {
		return new Promise((resolve, reject) => {
			uni.request({
				method: 'GET',
				url: url,
				data: data,
				header: {
					'content-type': 'application/json'
				},
				dataType: 'json',
				success: (res) => {
					resolve(res.data);
				},
				fail: (err) => {
					uni.showToast({
						title: "接口请求失败",
						icon: 'none'
					})
					reject(err)
				}
			})
		});
	},
	
	post(url, data) {
		return new Promise((resolve, reject) => {
			uni.request({
				method: 'POST',
				url: url,
				data: data,
				header: {
					'content-type': 'application/json'
				},
				dataType: 'json',
				success: (res) => {
					resolve(res.data)
				},
				fail: (err) => {
					uni.showToast({
						title: "接口请求失败",
						icon: 'none'
					})
					reject(err)
				}
			})
		});
	},
	
	delete(url, data) {
		return new Promise((resolve, reject) => {
			uni.request({
				method: 'DELETE',
				url: url,
				data: data,
				header: {
					'content-type': 'application/json'
				},
				dataType: 'json',
				success: (res) => {
					resolve(res.data)
				},
				fail: (err) => {
					uni.showToast({
						title: "接口请求失败",
						icon: 'error'
					})
					reject(err)
				}
			})
		});
	},
	
	put(url, data) {
		let token = uni.getStorageSync('token');

		return new Promise((resolve, reject) => {
			uni.request({
				method: 'PUT',
				url: url,
				data: data,
				header: {
					'content-type': 'application/json'
				},
				dataType: 'json',
				success: (res) => {
					resolve(res.data)
				},
				fail: (err) => {
					uni.showToast({
						title: "接口请求失败",
						icon: 'none'
					})
					reject(err)
				}
			})
		});
	}
}
